set.seed(1)
data(instacart)
Column
Histogram of Number of Items per Order
instacart %>%
group_by(order_id) %>%
mutate( #add column for number of items in order
n_items = n()
) %>%
plot_ly(x = ~n_items, type = "histogram") %>%
layout(
title = "Distribution of Number of Items per Order",
xaxis = list(title = "# Items"),
yaxis = list(title = "Orders")
)
Column
Boxplot of Order Times in Top Departments
top_departments =
instacart %>%
count(department, sort = TRUE) %>%
top_n(6)
## Selecting by n
inner_join(instacart, top_departments, by = "department") %>%
plot_ly(y = ~order_hour_of_day, color = ~department,
type = "box", colors = "Set2") %>%
layout(
title = "Order Times for Top 6 Departments",
xaxis = list(title = "Department"),
yaxis = list(title = "Hour of Day")
)
Barplot of Most Popular Aisles
instacart %>%
count(aisle, sort = TRUE, name = "n_items") %>%
filter(n_items > 10000) %>%
plot_ly(x = ~aisle, y = ~n_items,
color = ~aisle, type = "bar") %>%
layout(
title = "Most Popular ShoppingAisles",
xaxis = list(
title = "Aisle",
categoryorder = "array",
categoryarray = ~aisle),
yaxis = list(title = "# items")
)
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors